# 处理多张图片
import numpy as np
import glob as glob
import cv2
import os
 
# Returns a list of all folders with participant numbers
# img_path = glob.glob("F:/test/*jpg")
# for path in img_path:
#     img  = cv2.imread(path)
#     cv2.imshow('img',img)
#     cv2.waitKey(1000)
 
path_0 = "./tile_floor_up/"
if not os.path.exists(path_0):
	os.makedirs(path_0)
	print(path_0 + ' mkdir')

path_1 = "./tile_floor_down/"
if not os.path.exists(path_1):
	os.makedirs(path_1)
	print(path_1 + ' mkdir')

# 循环处理列表中的所有图片
path = os.path.expanduser("./tile_floor/")
for f in os.listdir(path):
    # print(f.strip()[0:-4])
 
    path="./tile_floor/"+f.strip()
    print(path)
    img = cv2.imread(path)
    # cv2.imshow('img', img)
    # shap[0] height,shape[1] width
    hei = img.shape[0]
    wid = img.shape[1]

    wid_0 = 0
    wid_1 = int(wid)
    hei_0 = 0
    hei_1 = int(hei / 2)
    hei_2 = int(hei)
    roiImg_0 = img[hei_0:hei_1, wid_0:wid_1]
    roiImg_1 = img[hei_1:hei_2, wid_0:wid_1]
    # cv2.imshow("[ROIImg]", roiImg)

    path_up = path_0 +f.strip()[0:-4]+"_"+ str('up') + ".jpg"
    cv2.imwrite(path_up, roiImg_0, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
    path_down = path_1 +f.strip()[0:-4]+"_"+ str('floor') + ".jpg"
    cv2.imwrite(path_down, roiImg_1, [int(cv2.IMWRITE_JPEG_QUALITY), 100])